<?php
  
  $str = $_GET['str'];
  
  if (strlen($str) == 0) exit;

  $con = mysql_connect("mysql1.000webhost.com", "a7424976_info", "thebest5");
	$res = mysql_select_db("a7424976_info");
	
	$queryres = mysql_query("select distinct name from inventory");

	while(($row = mysql_fetch_row($queryres))){
		if (stripos($row[0], $str) !== FALSE){
			$q1 = mysql_query("select COUNT(*) from inventory where name='$row[0]' and state=0");
			$q2 = mysql_query("select COUNT(*) from inventory where name='$row[0]' and state=1");
			$num1 = mysql_fetch_row($q1);
			$num2 = mysql_fetch_row($q2);
			
			$num = (int)$num1[0] - (int)$num2[0];
			echo "$row[0]-$num+";
		}
	}

  	mysql_close($con);
?>